package com.awspaas.user.apps.shhtaerospaceindustrial.extbutton;

import java.util.List;
import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListenerInterface;
import com.actionsoft.exception.BPMNError;
import com.actionsoft.sdk.local.SDK;

public class validateUnitWritePsnFIle implements InterruptListenerInterface {
	@Override
	public boolean execute(ProcessExecutionContext processExecutionContext) throws Exception {
		String processInstId = processExecutionContext.getProcessInstance().getId();
		List<BO> ceitemlist = SDK.getBOAPI().query("BO_EU_SHHT_SPFGRY_MX", true)
				.addQuery("BINDID =", processInstId).asc().list();
		
		if (ceitemlist != null && !ceitemlist.isEmpty()) {
			for (int i = 0; i < ceitemlist.size(); i++) {
//				JSONObject orderItem = new JSONObject();
				BO ceitembo = ceitemlist.get(i);
				String ID = objToStr(ceitembo.get("ID"));
				Object PSNNAME = objToStr(ceitembo.get("PSNNAME"));
				Object XQLASTYANGDATE = objToStr(ceitembo.get("XQLASTYANGDATE"));
				if (XQLASTYANGDATE == null || ("").equals(XQLASTYANGDATE)) {
					throw new BPMNError(PSNNAME + "所在小区最后一次阳性病例发生日期没填写.");
				}
				
				Object PSNFILE = objToStr(ceitembo.get("PSNFILE"));
				if (PSNFILE == null || ("").equals(PSNFILE)) {
					throw new BPMNError(PSNNAME + "所在小区，三区划分证明文件还未上传.");
				}

			}
		}

		return true;
	}

	public static String objToStr(Object obj) {
		return obj == null ? "" : obj.toString();
	}

	@Override
	public String getDescription() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getProvider() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getVersion() {
		// TODO Auto-generated method stub
		return null;
	}
}
